import { List, Cell } from 'react-vant'
import { getUserUp, getUserFans } from '../../../api/user'
import { useState } from 'react'
import Item from './item'

export default (props) => {
    const [list, setList] = useState([]);
    const [page, setPage] = useState(1);
    const [finished, setFinished] = useState(false);
    
    async function getData() {
        if (props.class === 0) {
            const { data } = await getUserUp({
                page,
                id: props.id
            })
            setPage(v => v + 1)
            console.log(data);
            return data.data.results
        } else {
            const { data } = await getUserFans({
                page,
                id: props.id
            })
            console.log(data);
            setPage(v => v + 1)
            return data.data.results
        }
    }
    const onLoad = async () => {
        // 异步更新数据
        const data = await getData();
        setList((v) => [...v, ...data]);
        if (list.length < 10) {
            setFinished(true);
        }
    };
    return (
        <List finished={finished} onLoad={onLoad}>
            {list.length
                ? list.map((item, index) => {
                    return <Item key={index} data={item} class={props.class} />;
                })
                : null}
        </List>
    )
}